package cn.liu.jetpack_demo.pages.user.list

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import cn.liu.jetpack_demo.api.UserApi
import cn.liu.jetpack_demo.pages.user.components.ListItem

@Composable
fun UserListPage(navController: NavController) {
  val users = UserApi.getUsers()
  LazyColumn(
    contentPadding = PaddingValues(all = 12.dp),
    verticalArrangement = Arrangement.spacedBy(12.dp)
  ) {
//    items(users) {
//      ListItem(it)
//    }
    itemsIndexed(items = users, key = { index, person -> person.id}) {index, person ->
      Log.d("userlistpage", "index:: $index")
      ListItem(person)
    }
  }
}


@Preview(name = "UserListPage")
@Composable
private fun PreviewView() {
  UserListPage(
    navController = rememberNavController()
  )
}